import { observable, action } from 'mobx';
import http from '../common/http';
import paramInspect from '../common/paramInspect';

class ContributionStore {
  constructor(rootStore) {
    this.rootStore = rootStore
  }

  @observable contributionParam = {
    "type": 2,
    "endTime": "",
    "pageIndex": 1,
    "pageSize": 10,
    "source": "",
    "startTime": "",
    "status": "",
    "title": "",
    "delState": false
  }
  @observable contributionList = [];
  @observable contributionListTotal = 0;
  @observable contributionLoadSuccess = false;

  @action toGetContributionList = () => {
    this.rootStore.globalStore.toShowLoding();
    http.get('/contributeBoss/listContribute', paramInspect(this.contributionParam))
    .then((response) => {
      this.rootStore.globalStore.toHideLoading();
      if (response.success) {
        this.contributionLoadSuccess = true;
        this.contributionList = response.data.dataList;
        this.contributionListTotal = response.data.total;
      }
    })
  }

  @action toChangePageNumber = (pageNumber) => {
    this.contributionParam.pageIndex = pageNumber;
    this.toGetContributionList();
  }

  @action toChangePageSize = (pageSize) => {
    this.contributionParam.pageIndex = 1;
    this.contributionParam.pageSize = pageSize;
    this.toGetContributionList();
  }

  @action filterParamSearch = (param) => {
    this.contributionParam.title = param.title;
    this.contributionParam.startTime = param.startTime;
    this.contributionParam.endTime = param.endTime;
    this.contributionParam.pageIndex = 1;
    this.contributionParam.categoryId = ""
    this.toGetContributionList();
  }

  @action toChangeListStatus = (status) => {
    this.contributionParam.history = "";
    this.contributionParam.pageIndex = 1;
    this.contributionParam.pageSize = 10;
    this.contributionParam.status = status;
    this.toGetContributionList();
  }

  @action toGetHistory = (status) => {
    this.contributionParam.history = true;
    this.contributionParam.pageIndex = 1;
    this.contributionParam.pageSize = 10;
    this.contributionParam.status = status;
    this.toGetContributionList();
  }

  @action toChangeCategoryFilter = (item, id) => {
    this.contributionParam.categoryId = id;
    this.toGetContributionList();
  }

  @action toChangeFinance = (type) => {
    this.contributionParam.history = "";
    this.contributionParam.closeAnAccount = type;
    this.contributionParam.status = "";
    this.toGetContributionList();
  }

  @observable categoryParamFifty = {
    "ascOrDesc": "desc",
    "delState": false,
    "desc": "",
    "id": "",
    "local": "en",
    "name": "",
    "orderByColumn": "",
    "pageIndex": 1,
    "pageSize": 50,
    "parentId": "",
    "resultLimit": "",
  }

  @observable categoryListFifty = [];
  @observable categoryFiftyLoadSuccess = false;

  @action toGetNewsCategoryFifty = (local) => {
    this.categoryParamFifty.local = local;
    http.get('/news/category/page', paramInspect(this.categoryParamFifty))
    .then((response) => {
      if (response.success) {
        this.categoryListFifty = response.data.dataList;
        this.categoryFiftyLoadSuccess = true
      }
    })
  }

  @observable financeStatistics = {
    articleCount: 0,
    createUserCount: 0,
    settledAmount: 0
  }

  @action toGetStatistics = () => {
    const param = {
      closeAnAccount: 1
    }

    http.get('/contributeBoss/contributeStatistics', param)
    .then((response) => {
      if (response.success) {
        this.financeStatistics.articleCount = response.data.articleCount
        this.financeStatistics.createUserCount = response.data.createUserCount
        this.financeStatistics.settledAmount = response.data.settledAmount
      }
    })
  }

}


export default ContributionStore;
